<template>
  <div :style="'width:' + width">
    <el-form label-position="left" :disabled="disabled">
      <el-form-item :required="required" :label="name">
        <el-checkbox v-model="data.value" @change="change" />
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  props: ['value', 'disabled', 'props', 'required', 'isBusiness'],
  data: function () {
    return {
      data: {
        value: false,
        displayName: '',
      },
    }
  },
  computed: {
    myprops() {
      return this.props ? this.props : []
    },
    width() {
      let val = this.myprops.find((x) => x.FLPR_Code == 'width')
      if (val) {
        if (this.isBusiness) {
          return val.BFFP_Value ? val.BFFP_Value : '100%'
        } else {
          return val.FFLP_Value ? val.FFLP_Value : '100%'
        }
      }
      return '100%'
    },
    name() {
      let val = this.myprops.find((x) => x.FLPR_Code == 'name')
      if (val) {
        if (this.isBusiness) {
          return val.BFFP_Value ? val.BFFP_Value : '判断选择器'
        } else {
          return val.FFLP_Value ? val.FFLP_Value : '判断选择器'
        }
      }
      return '判断选择器'
    },
  },
  methods: {
    change() {
      this.data.displayName = `${this.name} ${this.data.value ? '√' : '×'}`
      this.$emit('input', JSON.stringify(this.data))
      this.$emit('display', this.data.displayName)
    },
  },
  mounted: function () {
    if (this.value && Object.keys(this.value).length) {
      this.data = JSON.parse(this.value)
    } else {
      this.change()
    }
  },
}
</script>
<style scoped>
.el-form-item {
  margin: 10px !important;
}
</style>